export const Util = {
    // 信息存储
    Storage: {
        // 删除本地
        delLocal: (key: string) => window.localStorage.removeItem(key),
        // 设置本地
        setLocal: (key: string, value: unknown) => window.localStorage.setItem(key, JSON.stringify(value)),
        // 获取本地存储数据
        getLocal: (key: string) => {
            const local = window.localStorage.getItem(key);
            if (local !== null) {
                try {
                    return JSON.parse(local);
                } catch {
                    return local;
                }
            }
            return null;
        },
        // 删除会话
        delSession: (key: string) => window.sessionStorage.removeItem(key),
        // 设置会话
        setSession: (key: string, value: unknown) => window.sessionStorage.setItem(key, JSON.stringify(value)),
        // 获取会话
        getSession: (key: string) => {
            const local = window.sessionStorage.getItem(key);
            if (local !== null) {
                try {
                    return JSON.parse(local);
                } catch {
                    return local;
                }
            }
            return null;
        },
    }
}